package cz.vutbr.fit.xzemko01.tfmcbs.validation;

import java.util.Map;

import org.eclipse.emf.common.util.DiagnosticChain;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EObjectValidator;

import cz.vutbr.fit.xzemko01.tfmcbs.model.Artifact;
import cz.vutbr.fit.xzemko01.tfmcbs.model.CompositeComponent;
import cz.vutbr.fit.xzemko01.tfmcbs.model.Delegate;
import cz.vutbr.fit.xzemko01.tfmcbs.model.Dependency;
import cz.vutbr.fit.xzemko01.tfmcbs.model.Generalization;
import cz.vutbr.fit.xzemko01.tfmcbs.model.Interface;
import cz.vutbr.fit.xzemko01.tfmcbs.model.Manifestation;
import cz.vutbr.fit.xzemko01.tfmcbs.model.Model;
import cz.vutbr.fit.xzemko01.tfmcbs.model.ProvidingPort;
import cz.vutbr.fit.xzemko01.tfmcbs.model.Realization;
import cz.vutbr.fit.xzemko01.tfmcbs.model.RequiringPort;
import cz.vutbr.fit.xzemko01.tfmcbs.model.SimpleComponent;
import cz.vutbr.fit.xzemko01.tfmcbs.model.Usage;
import cz.vutbr.fit.xzemko01.tfmcbs.validation.validators.ArtifactValidator;
import cz.vutbr.fit.xzemko01.tfmcbs.validation.validators.CompositeComponentValidator;
import cz.vutbr.fit.xzemko01.tfmcbs.validation.validators.DelegateValidator;
import cz.vutbr.fit.xzemko01.tfmcbs.validation.validators.DependencyValidator;
import cz.vutbr.fit.xzemko01.tfmcbs.validation.validators.GeneralizationValidator;
import cz.vutbr.fit.xzemko01.tfmcbs.validation.validators.InterfaceValidator;
import cz.vutbr.fit.xzemko01.tfmcbs.validation.validators.ManifestationValidator;
import cz.vutbr.fit.xzemko01.tfmcbs.validation.validators.ModelValidator;
import cz.vutbr.fit.xzemko01.tfmcbs.validation.validators.ProvidingPortValidator;
import cz.vutbr.fit.xzemko01.tfmcbs.validation.validators.RealizationValidator;
import cz.vutbr.fit.xzemko01.tfmcbs.validation.validators.RequiringPortValidator;
import cz.vutbr.fit.xzemko01.tfmcbs.validation.validators.SimpleComponentValidator;
import cz.vutbr.fit.xzemko01.tfmcbs.validation.validators.UsageValidator;

public class ValidatorAdapter extends EObjectValidator {

	@Override
	public boolean validate(EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context) {
		return validate(eObject.eClass(), eObject, diagnostics, context);
	}
	
	@Override
	public boolean validate(EClass eClass, EObject eObject, 
						DiagnosticChain diagnostics, Map<Object, Object> context) 
	{	
		boolean result = true;

		if(eObject instanceof Model) {
			result = ModelValidator.getInstance().validate((Model)eObject, diagnostics, context);
		} else if(eObject instanceof Interface) {
			result = InterfaceValidator.getInstance().validate((Interface)eObject, diagnostics, context);
		} else if(eObject instanceof Artifact) {
			result = ArtifactValidator.getInstance().validate((Artifact) eObject, diagnostics, context);
		} else if(eObject instanceof SimpleComponent) {
			result = SimpleComponentValidator.getInstance().validate((SimpleComponent)eObject, diagnostics, context);
		} else if(eObject instanceof CompositeComponent) {
			result = CompositeComponentValidator.getInstance().validate((CompositeComponent)eObject, diagnostics, context);
		} else if(eObject instanceof Generalization) {
			result = GeneralizationValidator.getInstance().validate((Generalization) eObject, diagnostics, context);
		} else if(eObject instanceof Dependency) {
			result = DependencyValidator.getInstance().validate((Dependency) eObject, diagnostics, context);
		} else if(eObject instanceof Manifestation) {
			result = ManifestationValidator.getInstance().validate((Manifestation) eObject, diagnostics, context);
		} else if(eObject instanceof Realization) {
			result = RealizationValidator.getInstance().validate((Realization) eObject, diagnostics, context);
		} else if(eObject instanceof Usage) {
			result = UsageValidator.getInstance().validate((Usage) eObject, diagnostics, context);
		} else if(eObject instanceof Delegate) {
			result = DelegateValidator.getInstance().validate((Delegate) eObject, diagnostics, context);
		} else if(eObject instanceof RequiringPort) {
			result = RequiringPortValidator.getInstance().validate((RequiringPort) eObject, diagnostics, context);
		} else if(eObject instanceof ProvidingPort) {
			result = ProvidingPortValidator.getInstance().validate((ProvidingPort) eObject, diagnostics, context);
		}
		
		return result;
	}
}
